//
//  LGOutpatientRecordTextCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/9.
//

#import "LGOutpatientRecordTextCell.h"

@interface LGOutpatientRecordTextCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *typeButton;
/**   */
@property (nonatomic , strong)UIButton *dateButton;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;

@end

@implementation LGOutpatientRecordTextCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [self.typeButton setTitle:LGNSString(dataDic[@"visit_record_type_str"]) forState:UIControlStateNormal];
    self.typeButton.selected = [dataDic[@"visit_record_type_str"] isEqualToString:@"住院记录"]?YES:NO;
    CGFloat typeWidth = [LGNSString(dataDic[@"visit_record_type_str"]) textWidthWithFont:LGFontWeight(16, UIFontWeightMedium) maxHeight:MAXFLOAT];
    self.typeButton.frame = CGRectMake(0, viewPix(16), typeWidth+viewPix(30), viewPix(27));
    [self.dateButton setTitle:LGNSString(dataDic[@"datestr"]) forState:UIControlStateNormal];
    [self.dateButton setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:0];
    if(LGNSString(dataDic[@"kesmc"]).length>0){
        self.titleLabel.text = [NSString stringWithFormat:@"%@    %@",dataDic[@"kesmc"],dataDic[@"ysxm"]];
    }else{
        self.titleLabel.text = LGNSString(dataDic[@"ysxm"]);
    }
    self.contentLabel.text = LGNSString(dataDic[@"zdmc"]);
    CGFloat bottom = (LGNSString(dataDic[@"zdmc"]).length>0)?-viewPix(16):0;
    [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.baseView).offset(bottom);
    }];
}

-(void)createSubView{
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.typeButton];
    [self.baseView addSubview:self.dateButton];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
    }];
    [self.dateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(16));
        make.centerY.equalTo(self.typeButton);
        make.width.equalTo(@(viewPix(150)));
        make.height.equalTo(@(viewPix(25)));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.typeButton.mas_bottom).offset(viewPix(15));
        make.left.equalTo(self.baseView).offset(viewPix(16));
        make.right.equalTo(self.baseView).offset(-viewPix(16));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(10));
        make.left.right.equalTo(self.titleLabel);
        make.bottom.equalTo(self.baseView).offset(-viewPix(16));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:8];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}


-(UIButton *)typeButton{
    if(!_typeButton){
        _typeButton = [UIButton buttonWithTitle:@"门诊记录" titleFont:LGFontWeight(16, UIFontWeightMedium) normalColor:@"#1F6CC6" selectColor:@"#189090"];
        [_typeButton setBackgroundImage:[UIImage imageNamed:@"就诊检查-蓝色"] forState:UIControlStateNormal];
        [_typeButton setBackgroundImage:[UIImage imageNamed:@"就诊检查-绿色"] forState:UIControlStateSelected];
        _typeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _typeButton.frame = CGRectMake(0, viewPix(16), viewPix(102), viewPix(27));
        _typeButton.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(16), 0, 0);
        _typeButton.userInteractionEnabled = NO;
    }
    return _typeButton;
}


-(UIButton *)dateButton{
    if(!_dateButton){
        _dateButton = [UIButton buttonWithTitle:@"2021年12月21日"  titleFont:LGFont(16) textColor:@"#666666" imageName:@"grayTip16"];
        _dateButton.bounds = CGRectMake(0, 0, viewPix(150), viewPix(25));
        _dateButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [_dateButton setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:0];
        _dateButton.userInteractionEnabled = NO;
    }
    return _dateButton;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"心脏内科医疗单元   陈琦" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"冠心病、高血压2级，高危" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _contentLabel;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
